from django.db import models

from fgww.utils.models import BaseModel
# Create your models here.


class CategoryModel(BaseModel):
    name = models.CharField(max_length=32, verbose_name='课程分类名称')
    parent = models.ForeignKey('self', on_delete=models.CASCADE, related_name='son', verbose_name='父级分类')
    recommend = models.BooleanField(default=False, verbose_name='是否推荐')
    ishot = models.BooleanField(default=False, verbose_name='是否热门')
    isgood = models.BooleanField(default=False, verbose_name='是否精品')

    class Meta:
        db_table = "fg_category"

    def __str__(self):
        return self.name


class TeacherModel(BaseModel):
    name = models.CharField(max_length=32, verbose_name='教师名称')
    image = models.ImageField(upload_to='teacher', verbose_name='教师头像')
    job = models.CharField(max_length=32, verbose_name='教师职位')
    intro = models.TextField(verbose_name='教师简介')
    sales = models.IntegerField(verbose_name='课程销量')

    class Meta:
        db_table = "fg_teacher"

    def __str__(self):
        return self.name


class CourseModel(BaseModel):
    name = models.CharField(max_length=32, verbose_name='课程名称')
    image = models.ImageField(upload_to='course', verbose_name='课程图片')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='课程价格')
    level = models.CharField(max_length=32, verbose_name='课程难度',choices=[(0,'初级'),(1,'中级'),(2,'高级')],default=1 )
    learn_num = models.IntegerField(verbose_name='学习人数')
    category = models.ForeignKey("CategoryModel", on_delete=models.CASCADE, related_name='course',verbose_name='课程分类')
    teacher = models.ForeignKey("TeacherModel", on_delete=models.CASCADE, related_name='course',verbose_name='授课教师')
    intro = models.TextField(verbose_name='课程简介')
    ishome = models.BooleanField(default=False,verbose_name='是否首页推荐')

    class Meta:
        db_table = "fg_course"

    def __str__(self):
        return self.name
